$(function () {
    var worf;
    var people;
    var police;
    $("#input").change(function () {
        var number = $("#input").val();
        if (number < 6 || number > 18) {
            alert("请输入4-18的数字");
        } else {
            $("#range").val(number);   //把输入框的值赋给滑块
        }
    });
    $("#range").change(function () {
        var range = $("#range").val();
        $("#input").val(range);  //把滑块的值赋给输入框
    });

    $(".range button").eq(0).click(function () {
        var number = $("#input").val();
        if (number > 6) {
            $("#input").val($("#input").val() - 1);
            $("#range").val($("#range").val() - 1);
        } else {
            alert("人数太少了")
        }
    })

    $(".range button").eq(1).click(function () {
        var number = $("#input").val();
        if (number < 18) {
            $("#input").val(parseInt($("#input").val()) + 1);
            $("#range").val(parseInt($("#range").val()) + 1);
        } else {
            alert("人数太多了")
        }
    })

    $(".pick button").click(function () {
        var num = Number($("#input").val());
        switch (num) {
            case 7:
            case 8:
                worf = 1;
                police = 1;
                people = num - worf - police;
                break;
            case 9:
            case 10:
            case 11:
                worf = 2;
                police = 2;
                people = num - worf - police;
                break;
            case 12:
            case 13:
            case 14:
            case 15:
                worf = 3;
                police = 3;
                people = num - worf - police;
                break;
            case 16:
            case 17:
            case 18:
            case 19:
                worf = 4;
                police = 4;
                people = num - worf - police;
                break;
            default:
                worf = 1;
                police = 1;
                people = num - worf - police;
        };
        var li=$('.rightsection li')
        li.eq(0).text('杀手'+worf+'人').css('color','red');
        li.eq(1).text('警察'+police+'人').css('color','blue');
        li.eq(2).text('平民'+people+'人').css('color','orange');
        var arr=[];                 //数字数组
        arr.push(worf,police,people);
        var arr1=[];                 //由杀手、警察、平民组成的数组
        for(var i=0;i<worf;i++){
            arr1.push("杀手")
        };
        for(var i=0;i<police;i++){
            arr1.push("警察")
        };
        for(var i=0;i<people;i++){
            arr1.push("平民")
        };
        localStorage.setItem("gameNumber",JSON.stringify(arr1));
    });

    $('.fp').click(function () {
        if(!people){
           alert('请先设置人数');
        }else{
            window.location='task2-3.html'
            // window.location='task2-3.html?worf='+worf+'&police='+police+'&people='+people;
            // window.location=`task2-3.html?worf=${worf}&police=${police}&people='${people}` //es6写法
        }
    })
});
